using System;
using System.Collections.Generic;
using System.Text;
using AF_ORM.CORE;
using System.Data;
using System.Data.SqlClient;
using Bussiness.Entity;
using log4net;
namespace Bussiness.Manager
{


    public class PT_ServiceBillDetailManager : Bussiness.ManagerBase.PT_ServiceBillDetailManagerBase
    {
        private static readonly ILog _logger = LogManager.GetLogger(typeof(PT_ServiceBillDetailManager).Name);
        public static PT_ServiceBillDetailManager CreateInstant()
        {
            return new PT_ServiceBillDetailManager();
        }

        public DataTable GetByBillNo(string billNo)
        {
            try
            {
                string sql = @" select D.ID,D.Bill_No 
                                ,S.ServiceCode
                                ,S.ServiceName
                                ,CASE WHEN D.Comment IS NOT NULL THEN D.Comment ELSE S.ServiceName END as Comment
                                ,D.Price AS Price
                                ,D.AgentPrice 
                                ,D.SaleOffMoney AS SaleOff
                                ,D.SaleOffReason AS SaleOffReason
                                ,D.Amount
                                ,D.OutPaid
                                ,D.IsDeleted
                                ,S.ServiceType
                            from PT_ServiceBillDetail  D INNER JOIN PT_ServiceList S ON D.ServiceCode = S.ServiceCode
                            where Bill_NO = @BillNo and D.IsDeleted = 0
                            order by IntCode
                        ";
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@BillNo", billNo);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql, param);
            }
            catch (Exception ex) {
                _logger.Debug(ex);
                return new DataTable();
            }
        }
        public PT_ServiceBillDetailEntity GetByID(Guid ID)
        {
            try
            {
                PT_ServiceBillDetailEntity cond = new PT_ServiceBillDetailEntity();
                cond.IsDeleted = false;
                cond.Id = ID;
                List<PT_ServiceBillDetailEntity> lst = SelectByIdLST(cond);
                if (lst != null && lst.Count > 0)
                {
                    return lst[0];
                }
                return null;
            }
            catch (Exception ex)
            {
                _logger.Debug(ex);
                return null;
            }
        }
    }
}

